home *** CD-ROM | disk | FTP | other *** search
/ MaxiMac 2000 December / MaxiMac 109.iso / Macworld on CD n°109 / Applications (Mac OS X PB) / MacOSX ScreenSavers / Source Code / Sproingees / sproingies.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-17  |  17.3 KB  |  796 lines  |  [????/????]

  1. /* -*- Mode: C; tab-width: 4 -*- */
  2. /* sproingies.c - 3D sproingies */
  3.  
  4. #if !defined( lint ) && !defined( SABER )
  5. static const char sccsid[] = "@(#)sproingies.c    4.04 97/07/28 xlockmore";
  6.  
  7. #endif
  8.  
  9. /*-
  10.  *  sproingies.c - Copyright 1996 by Ed Mackey, freely distributable.
  11.  *
  12.  * Permission to use, copy, modify, and distribute this software and its
  13.  * documentation for any purpose and without fee is hereby granted,
  14.  * provided that the above copyright notice appear in all copies and that
  15.  * both that copyright notice and this permission notice appear in
  16.  * supporting documentation.
  17.  *
  18.  * This file is provided AS IS with no warranties of any kind.  The author
  19.  * shall have no liability with respect to the infringement of copyrights,
  20.  * trade secrets or any patents by this file or any part thereof.  In no
  21.  * event will the author be liable for any lost revenue or profits or
  22.  * other special, indirect and consequential damages.
  23.  *
  24.  * Revision History:
  25.  * 07-Dec-96: Written.
  26.  */
  27.  
  28. #include <OpenGL/gl.h>
  29. #include <OpenGL/glu.h>
  30.  
  31. #include <stdio.h>
  32.  
  33. #include "buildlwo.h"
  34.  
  35. #define MAXSPROING 100
  36. #define T_COUNT 40
  37. #define BOOM_FRAME 50
  38.  
  39. struct sPosColor {
  40.     int         x, y, z, frame, life;
  41.     GLfloat     r, g, b;
  42. };
  43.  
  44.     int         rotx, roty, dist, wireframe, flatshade, groundlevel,
  45.                 maxsproingies, mono_sp;
  46.     int         sframe, target_rx, target_ry, target_dist, target_count;
  47.     GLuint      sproingies[6], TopsSides, SproingieBoom;
  48.     struct sPosColor *positions;
  49. static int  active_screens = 0;
  50.  
  51. void        SproingieSwap(void);
  52.  
  53. extern struct lwo LWO_s1_1, LWO_s1_2, LWO_s1_3, LWO_s1_4;
  54. extern struct lwo LWO_s1_5, LWO_s1_6, LWO_s1_b;
  55.  
  56. #include <stdlib.h>
  57.  
  58. #define LRAND rand
  59.  
  60. #define MAXRAND RAND_MAX
  61.  
  62.  
  63. static int
  64. myrand(int range)
  65. {
  66.     return ((int) (((float) range) * LRAND() / (MAXRAND)));
  67. }
  68.  
  69. static      GLuint
  70. build_TopsSides(int wireframe)
  71. {
  72.     GLuint      dl_num = 0;
  73.     GLfloat     mat_color[4] = {0.0, 0.0, 0.0, 1.0};
  74.  
  75.     dl_num = glGenLists(2);
  76.     if (!dl_num)
  77.         return (0);    /* 0 means out of display lists. */
  78.  
  79.     /* Surface: Tops */
  80.     glNewList(dl_num, GL_COMPILE);
  81.     mat_color[0] = 0.392157;
  82.     mat_color[1] = 0.784314;
  83.     mat_color[2] = 0.941176;
  84.     if (wireframe)
  85.         glColor3fv(mat_color);
  86.     else {
  87.         glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_color);
  88.     }
  89.     glEndList();
  90.  
  91.     /* Surface: Sides */
  92.     glNewList(dl_num + 1, GL_COMPILE);
  93.     mat_color[0] = 0.156863;
  94.     mat_color[1] = 0.156863;
  95.     mat_color[2] = 0.392157;
  96.     if (wireframe)
  97.         glColor3fv(mat_color);
  98.     else {
  99.         glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_color);
  100.     }
  101.     glEndList();
  102.     return (dl_num);
  103. }
  104.  
  105. static void
  106. LayGround(int sx, int sy, int sz, int width, int height)
  107. {
  108.     int         x, y, z, w, h;
  109.     GLenum      begin_polygon;
  110.  
  111.     if (wireframe)
  112.         begin_polygon = GL_LINE_LOOP;
  113.     else
  114.         begin_polygon = GL_POLYGON;
  115.  
  116.     if (!wireframe) {
  117.         if (!mono_sp)
  118.             glCallList(TopsSides);    /* Render the tops */
  119.         glNormal3f(0.0, 1.0, 0.0);
  120.  
  121.         for (h = 0; h < height; ++h) {
  122.             x = sx + h;
  123.             y = sy - (h << 1);
  124.             z = sz + h;
  125.             for (w = 0; w < width; ++w) {
  126.                 glBegin(begin_polygon);
  127.                 glVertex3i(x, y, z);
  128.                 glVertex3i(x, y, z - 1);
  129.                 glVertex3i(x + 1, y, z - 1);
  130.                 glVertex3i(x + 1, y, z);
  131.                 glEnd();
  132.                 glBegin(begin_polygon);
  133.                 glVertex3i(x + 1, y - 1, z);
  134.                 glVertex3i(x + 1, y - 1, z - 1);
  135.                 glVertex3i(x + 2, y - 1, z - 1);
  136.                 glVertex3i(x + 2, y - 1, z);
  137.                 glEnd();
  138.                 ++x;
  139.                 --z;
  140.             }
  141.         }
  142.     }
  143.     if (!mono_sp)
  144.         glCallList(TopsSides + 1);    /* Render the sides */
  145.     if (!wireframe)
  146.         glNormal3f(0.0, 0.0, 1.0);
  147.  
  148.     for (h = 0; h < height; ++h) {
  149.         x = sx + h;
  150.         y = sy - (h << 1);
  151.         z = sz + h;
  152.         for (w = 0; w < width; ++w) {
  153.             glBegin(begin_polygon);
  154.             glVertex3i(x, y, z);
  155.             glVertex3i(x + 1, y, z);
  156.             glVertex3i(x + 1, y - 1, z);
  157.             glVertex3i(x, y - 1, z);
  158.             glEnd();
  159.             glBegin(begin_polygon);
  160.             glVertex3i(x + 1, y - 1, z);
  161.             glVertex3i(x + 2, y - 1, z);
  162.             glVertex3i(x + 2, y - 2, z);
  163.             glVertex3i(x + 1, y - 2, z);
  164. /*-
  165.  * PURIFY 4.0.1 reports an unitialized memory read on the next line when using
  166.  * MesaGL 2.2 and -mono_sp.  This has been fixed in MesaGL 2.3 and later. */
  167.             glEnd();
  168.             ++x;
  169.             --z;
  170.         }
  171.     }
  172.  
  173.     /* Render the other sides */
  174.     if (!wireframe)
  175.         glNormal3f(1.0, 0.0, 0.0);
  176.  
  177.     for (h = 0; h < height; ++h) {
  178.         x = sx + h;
  179.         y = sy - (h << 1);
  180.         z = sz + h;
  181.         for (w = 0; w < width; ++w) {
  182.             glBegin(begin_polygon);
  183.             glVertex3i(x + 1, y, z);
  184.             glVertex3i(x + 1, y, z - 1);
  185.             glVertex3i(x + 1, y - 1, z - 1);
  186.             glVertex3i(x + 1, y - 1, z);
  187.             glEnd();
  188.             glBegin(begin_polygon);
  189.             glVertex3i(x + 2, y - 1, z);
  190.             glVertex3i(x + 2, y - 1, z - 1);
  191.             glVertex3i(x + 2, y - 2, z - 1);
  192.             glVertex3i(x + 2, y - 2, z);
  193.             glEnd();
  194.             ++x;
  195.             --z;
  196.         }
  197.     }
  198.  
  199.     if (wireframe) {
  200.         if (!mono_sp)
  201.             glCallList(TopsSides);    /* Render the tops */
  202.  
  203.         for (h = 0; h < height; ++h) {
  204.             x = sx + h;
  205.             y = sy - (h << 1);
  206.             z = sz + h;
  207.             for (w = 0; w < width; ++w) {
  208.                 glBegin(begin_polygon);
  209.                 glVertex3i(x, y, z);
  210.                 glVertex3i(x, y, z - 1);
  211.                 glVertex3i(x + 1, y, z - 1);
  212.                 glVertex3i(x + 1, y, z);
  213.                 glEnd();
  214.                 glBegin(begin_polygon);
  215.                 glVertex3i(x + 1, y - 1, z);
  216.                 glVertex3i(x + 1, y - 1, z - 1);
  217.                 glVertex3i(x + 2, y - 1, z - 1);
  218.                 glVertex3i(x + 2, y - 1, z);
  219.                 glEnd();
  220.                 ++x;
  221.                 --z;
  222.             }
  223.         }
  224.     }
  225. }
  226.  
  227. #define RESET_SPROINGIE (-30 + myrand(28))
  228.  
  229. static void
  230. AdvanceSproingie(int t)
  231. {
  232.     int         g_higher, g_back, t2;
  233.     struct sPosColor *thisSproingie = &(positions[t]);
  234.     struct sPosColor *S2 = &(positions[0]);
  235.  
  236.     if (thisSproingie->life > 0) {
  237.         if ((++(thisSproingie->frame)) > 11) {
  238.             if (thisSproingie->frame >= BOOM_FRAME) {
  239.                 if ((thisSproingie->r -= 0.08) < 0.0)
  240.                     thisSproingie->r = 0.0;
  241.                 if ((thisSproingie->g -= 0.08) < 0.0)
  242.                     thisSproingie->g = 0.0;
  243.                 if ((thisSproingie->b -= 0.08) < 0.0)
  244.                     thisSproingie->b = 0.0;
  245.                 if ((--(thisSproingie->life)) < 1) {
  246.                     thisSproingie->life = RESET_SPROINGIE;
  247.                 }
  248.                 return;
  249.             }
  250.             thisSproingie->x += 1;
  251.             thisSproingie->y -= 2;
  252.             thisSproingie->z += 1;
  253.             thisSproingie->frame = 0;
  254.  
  255.             for (t2 = 0; t2 < maxsproingies; ++t2) {
  256.                 if ((t2 != t) && (thisSproingie->x == S2->x) &&
  257.                     (thisSproingie->y == S2->y) && (thisSproingie->z == S2->z) &&
  258.                     (S2->life > 10) && (S2->frame < 6)) {
  259. #if 0
  260.                     if (thisSproingie->life > S2->life) {
  261.                         S2->life = 10;
  262.                     } else {
  263. #endif
  264.                         if (thisSproingie->life > 10) {
  265.                             thisSproingie->life = 10;
  266.                             thisSproingie->frame = BOOM_FRAME;
  267.                             if ((thisSproingie->r += 0.5) > 1.0)
  268.                                 thisSproingie->r = 1.0;
  269.                             if ((thisSproingie->g += 0.5) > 1.0)
  270.                                 thisSproingie->g = 1.0;
  271.                             if ((thisSproingie->b += 0.5) > 1.0)
  272.                                 thisSproingie->b = 1.0;
  273.                         }
  274. #if 0
  275.                     }
  276. #endif
  277.                 }
  278.                 ++S2;
  279.             }
  280.         }
  281.         if (!((thisSproingie->life == 10) &&
  282.               (thisSproingie->frame > 0) &&
  283.               (thisSproingie->frame < BOOM_FRAME))) {
  284.             if ((--(thisSproingie->life)) < 1) {
  285.                 thisSproingie->life = RESET_SPROINGIE;
  286.             } else if (thisSproingie->life < 9) {
  287.                 thisSproingie->frame -= 2;
  288.             }
  289.         }        /* else wait here for frame 0 to come about. */
  290.     } else if (++(thisSproingie->life) >= 0) {
  291.         if (t > 1) {
  292.             g_higher = -3 + myrand(5);
  293.             g_back = -2 + myrand(5);
  294.         } else if (t == 1) {
  295.             g_higher = -2 + myrand(3);
  296.             g_back = -1 + myrand(3);
  297.         } else {
  298.             g_higher = -1;
  299.             g_back = 0;
  300.         }
  301.  
  302.         thisSproingie->x = (-g_higher - g_back);
  303.         thisSproingie->y = (g_higher << 1);
  304.         thisSproingie->z = (g_back - g_higher);
  305.         thisSproingie->life = 40 + myrand(200);
  306.         thisSproingie->frame = -10;
  307.         thisSproingie->r = (GLfloat) (40 + myrand(200)) / 255.0;
  308.         thisSproingie->g = (GLfloat) (40 + myrand(200)) / 255.0;
  309.         thisSproingie->b = (GLfloat) (40 + myrand(200)) / 255.0;
  310.  
  311.         for (t2 = 0; t2 < maxsproingies; ++t2) {
  312.             if ((t2 != t) && (thisSproingie->x == S2->x) &&
  313.                 (thisSproingie->y == S2->y) && (thisSproingie->z == S2->z) &&
  314.                 (S2->life > 10) && (S2->frame < 0)) {
  315.                 /* If one is already being born, just wait. */
  316.                 thisSproingie->life = -1;
  317.             }
  318.             ++S2;
  319.         }
  320.     }
  321. }
  322.  
  323. static void
  324. NextSproingie()
  325. {
  326.     int         ddx, t;
  327.     struct sPosColor *thisSproingie = &(positions[0]);
  328.  
  329.     if (++sframe > 11) {
  330.         sframe = 0;
  331.         for (t = 0; t < maxsproingies; ++t) {
  332.             thisSproingie->x -= 1;
  333.             thisSproingie->y += 2;
  334.             thisSproingie->z -= 1;
  335.             ++thisSproingie;
  336.         }
  337.     }
  338.     for (t = 0; t < maxsproingies; ++t) {
  339.         AdvanceSproingie(t);
  340.     }
  341.  
  342.     if (target_count < 0) {    /* track to current target */
  343.         if (target_rx < rotx)
  344.             --rotx;
  345.         else if (target_rx > rotx)
  346.             ++rotx;
  347.  
  348.         if (target_ry < roty)
  349.             --roty;
  350.         else if (target_ry > roty)
  351.             ++roty;
  352.  
  353.         ddx = (target_dist - dist) / 8;
  354.         if (ddx)
  355.             dist += ddx;
  356.         else if (target_dist < dist)
  357.             --dist;
  358.         else if (target_dist > dist)
  359.             ++dist;
  360.  
  361.         if ((target_rx == rotx) && (target_ry == roty) &&
  362.             (target_dist == dist)) {
  363.             target_count = T_COUNT;
  364.             if (target_dist <= 32)
  365.                 target_count >>= 2;
  366.         }
  367.     } else if (--target_count < 0) {    /* make up new target */
  368.         target_rx = myrand(100) - 35;
  369.         target_ry = -myrand(90);
  370.         target_dist = 32 << myrand(2);    /* could be 32, 64, or 128, (previously or 256) */
  371.  
  372.         if (target_dist >= dist)    /* no duplicate distances */
  373.             target_dist <<= 1;
  374.     }
  375.     /* Otherwise just hang loose for a while here */
  376. }
  377.  
  378. #ifdef __AUXFUNCS__
  379. void
  380. PrintEm(void)
  381. {
  382.     int         t, count = 0;
  383.  
  384.     for (t = 0; t < maxsproingies; ++t) {
  385.         if (positions[t].life > 0)
  386.             ++count;
  387.     }
  388.     (void) printf("RotX: %d, RotY: %d, Dist: %d.  Targets: X %d, Y %d, D %d.  Visible: %d\n",
  389.          rotx, roty, dist, target_rx, target_ry, target_dist, count);
  390. }
  391.  
  392. void
  393. ResetEm(void)
  394. {
  395.     int         t;
  396.  
  397.     for (t = 0; t < maxsproingies; ++t) {
  398.         positions[t].x = 0;
  399.         positions[t].y = 0;
  400.         positions[t].z = 0;
  401.         positions[t].life = -2;
  402.         positions[t].frame = 0;
  403.     }
  404. }
  405.  
  406. void
  407. distAdd(void)
  408. {
  409.     if (dist < (1 << 16 << 4))
  410.         dist <<= 1;
  411. }
  412.  
  413. void
  414. distSubtract(void)
  415. {
  416.     if (dist > 1)
  417.         dist >>= 1;
  418. }
  419.  
  420. void
  421. rotxAdd(void)
  422. {
  423.     rotx = (rotx + 5) % 360;
  424. }
  425.  
  426. void
  427. rotxSubtract(void)
  428. {
  429.     rotx = (rotx - 5) % 360;
  430. }
  431.  
  432. void
  433. rotyAdd(void)
  434. {
  435.     roty = (roty + 5) % 360;
  436. }
  437.  
  438. void
  439. rotySubtract(void)
  440. {
  441.     roty = (roty - 5) % 360;
  442. }
  443.  
  444. void
  445. rotxBAdd(void)
  446. {
  447.     rotx = (rotx + 45) % 360;
  448. }
  449.  
  450. void
  451. rotxBSubtract(void)
  452. {
  453.     rotx = (rotx - 45) % 360;
  454. }
  455.  
  456. void
  457. rotyBAdd(void)
  458. {
  459.     roty = (roty + 45) % 360;
  460. }
  461.  
  462. void
  463. rotyBSubtract(void)
  464. {
  465.     roty = (roty - 45) % 360;
  466. }
  467.  
  468. #endif
  469.  
  470. static void
  471. RenderSproingie(int t)
  472. {
  473.     GLfloat     scale, pointsize, mat_color[4] =
  474.     {0.0, 0.0, 0.0, 1.0};
  475.     GLdouble    clipplane[4] =
  476.     {0.0, 1.0, 0.0, 0.0};
  477.     struct sPosColor *thisSproingie = &(positions[t]);
  478.  
  479.     if (thisSproingie->life < 1)
  480.         return;
  481.  
  482.     glPushMatrix();
  483.  
  484.     if (!mono_sp) {
  485.         mat_color[0] = thisSproingie->r;
  486.         mat_color[1] = thisSproingie->g;
  487.         mat_color[2] = thisSproingie->b;
  488.         if (wireframe)
  489.             glColor3fv(mat_color);
  490.         else {
  491.             glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_color);
  492.         }
  493.     }
  494.     if (thisSproingie->frame < 0) {
  495.         glEnable(GL_CLIP_PLANE0);
  496.         glTranslatef((GLfloat) (thisSproingie->x),
  497.                  (GLfloat) (thisSproingie->y) +
  498.                  ((GLfloat) (thisSproingie->frame) / 9.0),
  499.                  (GLfloat) (thisSproingie->z));
  500.         clipplane[3] = ((GLdouble) (thisSproingie->frame) / 9.0) +
  501.             (wireframe ? 0.0 : 0.1);
  502.         glClipPlane(GL_CLIP_PLANE0, clipplane);
  503.         glCallList(sproingies[0]);
  504.         glDisable(GL_CLIP_PLANE0);
  505.     } else if (thisSproingie->frame >= BOOM_FRAME) {
  506.         glTranslatef((GLfloat) (thisSproingie->x) + 0.5,
  507.                  (GLfloat) (thisSproingie->y) + 0.5,
  508.                  (GLfloat) (thisSproingie->z) - 0.5);
  509.         scale = (GLfloat) (1 << (thisSproingie->frame - BOOM_FRAME));
  510.         glScalef(scale, scale, scale);
  511.         if (!wireframe) {
  512.             if (!mono_sp)
  513.                 glColor3fv(mat_color);
  514.             glDisable(GL_LIGHTING);
  515.         }
  516.         pointsize = (GLfloat) ((BOOM_FRAME + 8) - thisSproingie->frame) -
  517.             (dist / 64.0);
  518.         glPointSize((pointsize < 1.0) ? 1.0 : pointsize);
  519. /*-
  520.  * PURIFY 4.0.1 reports an unitialized memory read on the next line when using
  521.  * MesaGL 2.2.  This has been tracked to MesaGL 2.2 src/points.c line 313. */
  522.         glCallList(SproingieBoom);
  523.         glPointSize(1.0);
  524.         if (!wireframe) {
  525.             glEnable(GL_LIGHTING);
  526.         }
  527.     } else if (thisSproingie->frame > 5) {
  528.         glTranslatef((GLfloat) (thisSproingie->x + 1),
  529.                  (GLfloat) (thisSproingie->y - 1), (GLfloat) (thisSproingie->z - 1));
  530.         glRotatef((GLfloat) - 90.0, 0.0, 1.0, 0.0);
  531.         glCallList(sproingies[thisSproingie->frame - 6]);
  532.     } else {
  533.         glTranslatef((GLfloat) (thisSproingie->x), (GLfloat) (thisSproingie->y),
  534.                  (GLfloat) (thisSproingie->z));
  535.         glCallList(sproingies[thisSproingie->frame]);
  536.     }
  537.  
  538.     glPopMatrix();
  539.  
  540. }
  541.  
  542. static void
  543. ComputeGround()
  544. {
  545.     int         g_higher, g_back, g_width, g_height;
  546.  
  547.     /* higher: x-1, y+2, z-1 */
  548.     /* back: x-1, y, z+1 */
  549.  
  550.     if (groundlevel == 0) {
  551.         g_back = 2;
  552.         g_width = 5;
  553.     } else if (groundlevel == 1) {
  554.         g_back = 4;
  555.         g_width = 8;
  556.     } else {
  557.         g_back = 8;
  558.         g_width = 16;
  559.     }
  560.  
  561.     if ((g_higher = dist >> 3) < 4)
  562.         g_higher = 4;
  563.     if (g_higher > 16)
  564.         g_higher = 16;
  565.     g_height = g_higher << 1;
  566.  
  567.     if (rotx < -10)
  568.         g_higher += (g_higher >> 2);
  569.     else if (rotx > 10)
  570.         g_higher -= (g_higher >> 2);
  571.  
  572. #if 0
  573.     if (dist > 128) {
  574.         ++g_higher;
  575.         ++g_back;
  576.         g_back <<= 1;
  577.     } else if (dist > 64) {
  578.         ++g_higher;
  579.         ++g_back;
  580.     } else if (dist > 32) {
  581.         /* nothing special */
  582.     } else {
  583.         if (g_higher > 2) {
  584.             g_higher = g_back = 4;
  585.         }
  586.     }
  587. #endif
  588.  
  589.     /* startx, starty, startz, width, height */
  590.     LayGround((-g_higher - g_back), (g_higher << 1), (g_back - g_higher),
  591.           (g_width), (g_height));
  592. }
  593.  
  594. void
  595. DisplaySproingies()
  596. {
  597.     int         t;
  598.     GLfloat     position[] =
  599.     {8.0, 5.0, -2.0, 0.1};
  600.  
  601.     if (wireframe)
  602.         glClear(GL_COLOR_BUFFER_BIT);
  603.     else
  604.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  605.  
  606.     glPushMatrix();
  607.     glTranslatef(0.0, 0.0, -(GLfloat) (dist) / 16.0);    /* viewing transform  */
  608.     glRotatef((GLfloat) rotx, 1.0, 0.0, 0.0);
  609.     glRotatef((GLfloat) roty, 0.0, 1.0, 0.0);
  610.  
  611.     if (!wireframe)
  612.         glLightfv(GL_LIGHT0, GL_POSITION, position);
  613.  
  614. #if 0                /* Show light pos */
  615.     glPushMatrix();
  616.     glTranslatef(position[0], position[1], position[2]);
  617.     glColor3f(1.0, 1.0, 1.0);
  618.     if (!wireframe) {
  619.         glDisable(GL_LIGHTING);
  620.     }
  621.     glCallList(SproingieBoom);
  622.     if (!wireframe) {
  623.         glEnable(GL_LIGHTING);
  624.     }
  625.     glPopMatrix();
  626. #endif
  627.  
  628.     glTranslatef((GLfloat) sframe * (-1.0 / 12.0) - 0.75,
  629.              (GLfloat) sframe * (2.0 / 12.0) - 0.5,
  630.              (GLfloat) sframe * (-1.0 / 12.0) + 0.75);
  631.  
  632.     if (wireframe)
  633.         ComputeGround();
  634.  
  635.  
  636.     if (!wireframe)
  637.         ComputeGround();
  638.  
  639.         for (t = 0; t < maxsproingies; ++t) {
  640.                 RenderSproingie(t);
  641.         }
  642.  
  643.  
  644.     glPopMatrix();
  645.     glFlush();
  646.  
  647.     SproingieSwap();
  648. }
  649.  
  650. void
  651. NextSproingieDisplay()
  652. {
  653.     NextSproingie();
  654.     DisplaySproingies();
  655. }
  656.  
  657. void
  658. CleanupSproingies()
  659. {
  660.     int         t;
  661.  
  662.     if (SproingieBoom) {
  663.         for (t = 0; t < 6; ++t)
  664.             glDeleteLists(sproingies[t], 1);
  665.  
  666.         glDeleteLists(TopsSides, 2);
  667.         glDeleteLists(SproingieBoom, 1);
  668.  
  669.         --active_screens;
  670.         SproingieBoom = 0;
  671.     }
  672.     if (positions) {
  673.         (void) free((void *) (positions));
  674.         positions = NULL;
  675.     }
  676. }
  677.  
  678. void
  679. InitSproingies(int wfmode, int grnd, int mspr, int screen, int numscreens,
  680.            int mono_sp)
  681. {
  682.     GLfloat     ambient[] =
  683.     {0.2, 0.2, 0.2, 1.0};
  684.     GLfloat     position[] =
  685.     {10.0, 1.0, 1.0, 10.0};
  686.     GLfloat     mat_diffuse[] =
  687.     {0.6, 0.6, 0.6, 1.0};
  688.     GLfloat     mat_specular[] =
  689.     {0.8, 0.8, 0.8, 1.0};
  690.     GLfloat     mat_shininess[] =
  691.     {50.0};
  692.  
  693.     int         t;
  694.  
  695.     active_screens++;
  696.     CleanupSproingies();
  697.  
  698.     if (mspr < 0)
  699.         mspr = 0;
  700.     if (mspr >= MAXSPROING)
  701.         mspr = MAXSPROING - 1;
  702.  
  703.     rotx = 0;
  704.     roty = -45;
  705.     dist = (16 << 2);
  706.     sframe = 0;
  707.     target_count = 0;
  708.     mono_sp = mono_sp;
  709.  
  710.     wireframe = flatshade = 0;
  711.  
  712.     if (wfmode == 2)
  713.         flatshade = 1;
  714.     else if (wfmode)
  715.         wireframe = 1;
  716.  
  717.     groundlevel = grnd;
  718.     maxsproingies = mspr;
  719.  
  720.     if (maxsproingies) {
  721.         positions = (struct sPosColor *) calloc(maxsproingies,
  722.                           sizeof (struct sPosColor));
  723.  
  724.         if (!(positions))
  725.             maxsproingies = 0;
  726.     }
  727.     for (t = 0; t < maxsproingies; ++t) {
  728.         positions[t].x = 0;
  729.         positions[t].y = 0;
  730.         positions[t].z = 0;
  731.         positions[t].life = (-t * ((maxsproingies > 19) ? 1 : 4)) - 2;
  732.         positions[t].frame = 0;
  733.     }
  734.  
  735. #if 0                /* Test boom */
  736.     positions[0].x = 0;
  737.     positions[0].y = 0;
  738.     positions[0].z = 0;
  739.     positions[0].life = 10;
  740.     positions[0].frame = BOOM_FRAME;
  741.     positions[0].r = 0.656863;
  742.     positions[0].g = 1.0;
  743.     positions[0].b = 0.656863;
  744. #endif
  745.  
  746.     if (!(TopsSides = build_TopsSides(wireframe)))
  747.         (void) fprintf(stderr, "build_TopsSides\n");
  748.  
  749.     if (!(sproingies[0] = BuildLWO_sp(wireframe, &LWO_s1_1)))
  750.         (void) fprintf(stderr, "BuildLWO_sp - 1\n");
  751.     if (!(sproingies[1] = BuildLWO_sp(wireframe, &LWO_s1_2)))
  752.         (void) fprintf(stderr, "BuildLWO_sp - 2\n");
  753.     if (!(sproingies[2] = BuildLWO_sp(wireframe, &LWO_s1_3)))
  754.         (void) fprintf(stderr, "BuildLWO_sp - 3\n");
  755.     if (!(sproingies[3] = BuildLWO_sp(wireframe, &LWO_s1_4)))
  756.         (void) fprintf(stderr, "BuildLWO_sp - 4\n");
  757.     if (!(sproingies[4] = BuildLWO_sp(wireframe, &LWO_s1_5)))
  758.         (void) fprintf(stderr, "BuildLWO_sp - 5\n");
  759.     if (!(sproingies[5] = BuildLWO_sp(wireframe, &LWO_s1_6)))
  760.         (void) fprintf(stderr, "BuildLWO_sp - 6\n");
  761.  
  762.     if (!(SproingieBoom = BuildLWO_sp(wireframe, &LWO_s1_b)))
  763.         (void) fprintf(stderr, "BuildLWO_sp - b\n");
  764.  
  765.     if (wireframe) {
  766.         glShadeModel(GL_FLAT);
  767.         glDisable(GL_LIGHTING);
  768.     } else {
  769.         if (flatshade) {
  770.             glShadeModel(GL_FLAT);
  771.             position[0] = 1.0;
  772.             position[3] = 0.0;
  773.         }
  774.         glEnable(GL_LIGHTING);
  775.         glEnable(GL_LIGHT0);
  776.         glDepthFunc(GL_LEQUAL);
  777.         glEnable(GL_DEPTH_TEST);
  778.  
  779.         glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
  780.         glLightfv(GL_LIGHT0, GL_POSITION, position);
  781.  
  782.         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
  783.         glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
  784.         glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
  785.  
  786.         /* glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); */
  787.         glCullFace(GL_BACK);
  788.         glEnable(GL_CULL_FACE);
  789.  
  790.         glFrontFace(GL_CW);
  791.         /* glEnable(GL_NORMALIZE); */
  792.     }
  793. }
  794.  
  795. /* End of sproingies.c */
  796.